package com.sunshine.timetable;

import android.content.Context;

import androidx.core.content.ContextCompat;

import java.util.ArrayList;
import java.util.List;

public class ColorUtils {

    /*
    用于储存课程名称，相同名称相同颜色，另设置除外
     */
    private List<String> lessonNames = new ArrayList<>();

    private Context context;

    public ColorUtils(Context context){
        this.context = context;
    }

    /**
     * 设置按钮背景色
     * @param lessonName
     * @param color
     * @return
     */
    public int setButtonBackground(String lessonName, String color){
        int color_int = 0;
        addLesson(lessonName);
        switch (color){
            case "0":color_int = setDefaultBackground(lessonName);break;
            case "1":color_int = ContextCompat.getColor(context,R.color.red);break;
            case "2":color_int = ContextCompat.getColor(context,R.color.orange);break;
            case "3":color_int = ContextCompat.getColor(context,R.color.purple);break;
            case "4":color_int = ContextCompat.getColor(context,R.color.shallow_green);break;
            case "5":color_int = ContextCompat.getColor(context,R.color.hard_blue);break;
            case "6":color_int = ContextCompat.getColor(context,R.color.hard_green);break;
            case "7":color_int = ContextCompat.getColor(context,R.color.shallow_blue);break;
            case "8":color_int = ContextCompat.getColor(context,R.color.hard_orange);break;
            case "9":color_int = ContextCompat.getColor(context,R.color.blue);break;
            case "10":color_int = ContextCompat.getColor(context,R.color.green);break;
            case "11":color_int = ContextCompat.getColor(context,R.color.hard_purple);break;
            case "12":color_int = ContextCompat.getColor(context,R.color.shallow_green2);break;
            case "13":color_int = ContextCompat.getColor(context,R.color.hard_pink);break;
            case "14":color_int = ContextCompat.getColor(context,R.color.shallow_blue2);
        }
        return color_int;
    }

    private void addLesson(String lessonName) {
        if(!hasLesson(lessonName)) lessonNames.add(lessonName);
    }

    private boolean hasLesson(String lessonName) {
        for(int i=0;i<lessonNames.size();i++){
            if(lessonNames.get(i).equals(lessonName)) return true;
        }
        return false;
    }

    private int setDefaultBackground(String lessonName) {
        int count;
        for(count = 0;count<lessonNames.size();count++){
            if(lessonNames.get(count).equals(lessonName)) break;
        }
        switch (count%14){
            case 0:return context.getResources().getColor(R.color.red);
            case 1: return context.getResources().getColor(R.color.orange);
            case 2:return context.getResources().getColor(R.color.purple);
            case 3: return context.getResources().getColor(R.color.shallow_green);
            case 4:return context.getResources().getColor(R.color.hard_blue);
            case 5: return context.getResources().getColor(R.color.hard_green);
            case 6:return context.getResources().getColor(R.color.shallow_blue);
            case 7:return context.getResources().getColor(R.color.hard_orange);
            case 8:return context.getResources().getColor(R.color.blue);
            case 9:return context.getResources().getColor(R.color.green);
            case 10:return context.getResources().getColor(R.color.hard_purple);
            case 11:return context.getResources().getColor(R.color.shallow_green2);
            case 12:return context.getResources().getColor(R.color.hard_pink);
            case 13: return context.getResources().getColor(R.color.shallow_blue2);
            default:return context.getResources().getColor(R.color.transparent);
        }
    }

}
